function XF_InlineMenu(menuId, menu)
{
	this.MenuId = menuId;
	this.Menu = menu;
}

function XF_HidingItem(timerId, menuName)
{
	this.TimerId = timerId;
	this.MenuName = menuName;
}

function XF_ContextMenuItem(objRef, menu)
{
	this.ObjRef = objRef;
	this.Menu = menu;
}

function XF_MenuManager()
{
	this.Menus = new Array();
	this.InlineMenus = new Array();

	this.ContextMenus = new Array();
	this.HidingItems = new Array();
	
	this.ScriptURL = "";
}

XF_MenuManager.prototype.AddContextMenuToObject = function (objRef, menuName)
{
	var contextItem;
	
	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		if (menu.Name == menuName)
		{
			contextItem = new XF_ContextMenuItem(objRef, menu);
		}
	}

	this.ContextMenus[this.ContextMenus.length] = contextItem;

	objRef.oncontextmenu=XF_MenuOnContextMenu;
}

XF_MenuManager.prototype.GetMenu = function (menuName)
{
	var menuIdx;
	
	for (menuIdx in this.Menus)
	{
		if (this.Menus[menuIdx].Name == menuName)
		{
			return this.Menus[menuIdx];
		}
	}
	
	return null;
}

XF_MenuManager.prototype.InsertInlineMenu = function (menuName)
{
	var menu;
	var inlineMenu;
	var inlinePos;
	var menuIdx, inlineIdx;
	var html;
	
	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		if (menu.Name == menuName)
		{
			inlinePos = 0;
			for (inlineIdx in this.InlineMenus)
			{
				if (this.InlineMenus[inlineIdx].Menu.Name == menuName)
				{
					inlinePos++;
				}
			}
			
			inlineMenu = new XF_InlineMenu('xf_' + menuName + inlinePos, menu);

			if (xf_Is.nav4)
			{
				html =  "<IMG NAME=\"" + inlineMenu.MenuId + "anchor\" SRC=\"" + this.ScriptURL + "/fill.gif\" width=\"" + menu.Width() + "\" height=\"" + menu.Height() + "\">&nbsp;</IMG>";
			}
			else
			{
				html =  "<SPAN ID=\"" + inlineMenu.MenuId + "anchor\">&nbsp;</SPAN>";
			}
			
			document.write(html);

			this.InlineMenus[this.InlineMenus.length] = inlineMenu;
			menu.Inline = true;
		}
	}
}

XF_MenuManager.prototype.InsertMenuDefinitions = function ()
{
	var menu;
	var menuIdx;
	var inlineMenu;
	var inlineIdx;
	var html;
	
	html = "";
	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		
		html += "<DIV"
		html += " ID=\"xf_" + menu.Name + "\" ";
		html += "style=\"position:absolute;top:0px;left:0px;";
		html += "visibility:hidden;";
		//html += "display:none;";
		//html += "width:" + menu.Width() + "px;";
		//html += "height:" + (menu.Height()+2) + "px;";
		//html += "clip:rect(0px " + menu.Width() + "px " + (menu.Height()+2) + "px 0px);";
		html += "z-index:" + menu.ZIndex + ";";
		html += "overflow:hidden;";
		if (menu.BackgroundColor)
		{
			html += "background-color: " + menu.BackgroundColor + ";";
		}
		html += "\">";
		//html += menu.Render("xf_" + menu.Name);
		html += "</DIV>"
	}

	for (inlineIdx in this.InlineMenus)
	{
		inlineMenu = this.InlineMenus[inlineIdx];
		menu = inlineMenu.Menu;

		html += "<DIV ID=\"" + inlineMenu.MenuId + "\" ";
		html += "style=\"position:absolute;top:0px;left:0px;visibility:hidden;";
		//html += "width:" + menu.Width() + "px;";
		//html += "height:" + menu.Height() + "px;";
		//html += "clip:rect(0px " + menu.Width() + "px " + menu.Height() + "px 0px);";
		html += "z-index:" + menu.ZIndex + ";";
		html += "overflow:hidden;";
		if (menu.BackgroundColor)
		{
			html += "background-color: " + menu.BackgroundColor + ";";
		}
		html += "\">";
		//html += menu.Render(inlineMenu.MenuId);
		html += "</DIV>";
	}
	
	document.write(html);
}

XF_MenuManager.prototype.FillMenuDefinitions = function (bGenerate)
{
	
	var menu;
	var menuIdx;
	var inlineMenu;
	var inlineIdx;
	var layer;

	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		menu.Id = "xf_" + menu.Name;
		menu.Layer = XF_GetElementById("xf_" + menu.Name);

		if (typeof(bGenerate) == 'undefined' || bGenerate == true)
		{
			if (xf_Is.nav4)
			{
				menu.Layer.document.open();
				menu.Layer.document.write(menu.Render("xf_" + menu.Name));
				menu.Layer.document.close();
			}
			else
			{
				//alert('1');
				//alert(menu.Render("xf_" + menu.Name));
				//alert(menu.Layer.innerHTML);
				menu.Layer.innerHTML = menu.Render("xf_" + menu.Name);
				//alert('2');
			}
		}
	}
	
	for (inlineIdx in this.InlineMenus)
	{
		inlineMenu = this.InlineMenus[inlineIdx];
		menu = inlineMenu.Menu;
		
		menu.Id = inlineMenu.MenuId;
		menu.Layer = XF_GetElementById(inlineMenu.MenuId);

		if (typeof(bGenerate) == 'undefined' || bGenerate == true)
		{
			if (xf_Is.nav4)
			{
				menu.Layer.document.open();
				menu.Layer.document.write(menu.Render(inlineMenu.MenuId));
				menu.Layer.document.close();
			}
			else
			{
				menu.Layer.innerHTML = menu.Render(inlineMenu.MenuId)
			}
		}
	}
}

XF_MenuManager.prototype.AddMenu = function (menu)
{
	menu.Index = this.Menus.length;
	this.Menus[this.Menus.length] = menu;
}

XF_MenuManager.prototype.ShowInlineMenus = function ()
{
	var inlineIdx;
	var anchor;
	var menu;
	var xPos, yPos;
	for (inlineIdx in this.InlineMenus)
	{
		anchor = XF_GetElementById(this.InlineMenus[inlineIdx].MenuId + 'anchor');
		
		if (anchor != null)
		{
			menu = this.InlineMenus[inlineIdx].Menu;

			xPos = XF_GetXPosition(anchor);
			yPos = XF_GetYPosition(anchor);
			
			if (xf_Is.gecko)
			{
				var innerLayer;
				innerLayer = XF_GetElementById("xf_tbl_" + menu.Id);
				
				menu.Layer.style.width = XF_GetWidth(innerLayer);
			}

			menu.Move(xPos, yPos);
			XF_ShowElement(menu.Layer);
			
			return;
		}
	}
}

XF_MenuManager.prototype.ShowContextMenu = function (objRef, xPos, yPos)
{
	var contextIdx;
	var i = 0;
	
	for (i = 0; i < 25; i++)
	{
		for (contextIdx in this.ContextMenus)
		{
			if (this.ContextMenus[contextIdx].ObjRef == objRef)
			{
				xf_MenuManager.HideMenu(this.ContextMenus[contextIdx].Menu.Index, 1000);
				this.ContextMenus[contextIdx].Menu.Show(xPos, yPos);
				window.event.cancelBubble = true;
				return true;
			}
		}
		
		if (objRef.tagName == 'BODY')
		{
			return false;
		}

		if (xf_Is.gecko)
		{
			objRef = objRef.parentNode;
		}
		else
		{		
			objRef = objRef.parentElement;
		}
	}
	
	return false;
}

XF_MenuManager.prototype.ShowMenu = function (menuName, xPos, yPos)
{
	var menu;
	var menuIdx, inlineIdx;
	
	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		if (menu.Name == menuName)
		{
			/*
			if (menu.ShowCallBack != null)
			{
				if (!menu.ShowCallBack(menuName))
				{
					menu.CancelHide();
					//this.CancelHideMenu(menuName);
					return;
				}
			}
			*/
			menu.Parent = null;

			if (xf_Is.gecko)
			{
				var innerLayer;
				innerLayer = XF_GetElementById("xf_tbl_" + menu.Id);
				
				menu.Layer.style.width = XF_GetWidth(innerLayer);
			}

			menu.Move(xPos, yPos);

			XF_ShowElement(menu.Layer);
		}
	}
}

XF_MenuManager.prototype.ShowMenuParent = function (menuName, xPos, yPos, parentMenu)
{
	var menu;
	var menuIdx, inlineIdx;
	
	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		if (menu.Name == menuName)
		{
		
			if (menu.ShowCallBack != null)
			{
				if (!menu.ShowCallBack(menuName))
				{
					this.CancelHideMenu(menuName);
					return;
				}
			}
			menu.Parent = parentMenu;
			//menuElement = XF_GetElementById("xf_" + menu.Name);
			XF_MoveElementTo(menu.Layer, xPos, yPos);
			XF_ShowElement(menu.Layer);
		}
	}
}

XF_MenuManager.prototype.HideAll = function ()
{
	for (menuIdx in this.Menus)
	{
		menu = this.Menus[menuIdx];
		if (!menu.Inline)
		{
			menu.Hide(true);
		}
		else
		{
			if (menu.ShownMenu != null)
			{			
				menu.ShownMenu.Hide(true);
				
				menu.ShownMenu = null;
			}
		}
	}
}

XF_MenuManager.prototype.HideMenu = function (menuIndex, delay)
{
	var menu;

	if (typeof(menuIndex) == 'string')
	{
		menu = this.GetMenu(menuIndex);
		menuIndex = menu.Index;
	}
	else
	{
		menu = this.Menus[menuIndex];
	}
	
	if (arguments.length > 1)
	{
		if (menu.TimerId != null)
		{
			clearTimeout(menu.TimerId);
			menu.TimerId = null;
		}

		menu.TimerId = setTimeout("xf_MenuManager.HideMenu(" + menuIndex + ");", delay);

		return true;
	}
	else
	{
		if (menu.TimerId != null)
		{
			clearTimeout(menu.TimerId);
			menu.TimerId = null;

			menu.Hide(false);

			return true;
		}
	}

	return false;
}

XF_MenuManager.prototype.CancelHideMenu = function (menuName)
{
	for (hidingIdx in this.HidingItems)
	{
		if (this.HidingItems[hidingIdx] != null)
		{
			if (this.HidingItems[hidingIdx].MenuName == menuName)
			{
				clearTimeout(this.HidingItems[hidingIdx].TimerId);

				this.HidingItems[hidingIdx] = null;
				return true;
			}
		}
	}
	
	return false;
}

function XF_MenuItem(text, action, imageSrc, imageOver)
{
	this.Text = text;
	if (typeof(action) != 'undefined')
	{
		this.Action = action;
	}
	else
	{
		this.Action = null;
	}
	if (typeof(imageSrc) != 'undefined')
	{
		this.ImageSrc = imageSrc;
	}
	else
	{
		this.ImageSrc = null;
	}
	if (typeof(imageOver) != 'undefined')
	{
		this.ImageOver = imageOver;
	}
	else
	{
		this.ImageOver = null;
	}
	this.Function = null;
	this.Arguments = null;
	this.SubMenu = null;
}

function XF_Menu(menuName)
{
	// public variables
	this.Name = menuName;
	this.StyleSheet = null;
	this.CSSPrefix = null;
	this.Window = null;
	this.HeightFix = 0;
	this.WidthFix = 0;
	this.PaddingTop = 0;
	this.PaddingLeft = 0;
	this.PaddingRight = 0;
	this.PaddingBottom = 0;
	this.SeparatorColor = 'silver';
	this.SubMenuImageURL = null;
	this.OverFlowWidth = null;
	this.SubMenuImageWidth = 5;
	this.BeforeMenuImageURL = null;
	this.CellPadding = 0;
	this.CellSpacing = 0;
	this.SubMenuSpacing = 0;
	this.SubMenuVSpacing = 0;
	this.ZIndex = 10;

	// private variables
	this.Index = null;
	this.Items = new Array();
	this.ShownItem = null;
	this.ShownIdx = -1;
	this.bLock = false;
	this.Parent = null;
	this.Over = false;
	this.Layer = null;
	this.TimerId = null;
	this.Inline = false;
	this.XPos = 0;
	this.YPos = 0;

	this.HidingDelay = 1000;
}

XF_Menu.prototype.Width = function ()
{
	if (this.Layer != null)
	{
		return XF_GetWidth(this.Layer);
	}

	return 0;
}

XF_Menu.prototype.Height = function ()
{
	if (this.Layer != null)
	{
		return XF_GetHeight(this.Layer);
	}
	
	return 0;
}

XF_Menu.prototype.Show = function (xPos, yPos)
{
	/*if (this.ShowCallBack != null)
	{
		if (!this.ShowCallBack(this.Name))
		{
			return;
		}
	}*/

	if (xf_Is.gecko)
	{
		var innerLayer;
		innerLayer = XF_GetElementById("xf_tbl_" + this.Id);
		
		this.Layer.style.width = XF_GetWidth(innerLayer);
	}

	this.Move(xPos, yPos);
//alert('0');	
	XF_ShowElement(this.Layer);
}

XF_Menu.prototype.Hide = function (bForce)
{
	if (this.Over || (!bForce && this.ShownItem && this.ShownItem.Over))
	{
		return false;
	}
	
	if (this.bLock)
	{
		return false;
	}

	if(this.Inline)
	{
		this.Over = false;
		this.bLock = false;
		
		XF_MenuUnHighLightItem(this, true);
		return false;
	}
	
	if (this.ShownItem != null)
	{
		this.ShownItem.Hide(bForce);
		this.ShownItem = null;
	}
	
	if (this.Parent)
	{
		this.Parent.ShownItem = null;
		this.Parent.Hide(false);
	}
	
	if (this.HideCallBack != null)
	{
		this.HideCallBack(this.Name, this.HideCallBackArgs);
		//this.HideCallBack = null;
	}

	this.CancelHide();
	this.Over = false;
	this.bLock = false;
	
	XF_MenuUnHighLightItem(this, true);

	if (this.Layer != null)
	{
	//this.Layer.style.display = 'none';
		XF_HideElement(this.Layer);
	}
}

XF_Menu.prototype.CancelHide = function ()
{
	if (this.TimerId != null)
	{
		clearTimeout(this.TimerId);
		this.TimerId = null;
	}
}

XF_Menu.prototype.Lock = function ()
{
	this.bLock = true;
	
	if (this.Inline)
	{
		return;
	}

	if (this.Parent != null)
	{
		this.Parent.Lock();
	}
}

XF_Menu.prototype.UnLock = function ()
{
	this.bLock = false;
	
	if (this.Inline)
	{
		return;
	}

	if (this.Parent != null)
	{
		this.Parent.UnLock();
	}
}

XF_Menu.prototype.Move = function (xPos, yPos)
{
	if (document.body.clientWidth + document.body.scrollLeft < xPos + this.Width())
	{
		xPos = document.body.scrollLeft + document.body.clientWidth - this.Width() - 5;
	}
	if (document.body.clientHeight + document.body.scrollTop < yPos + this.Height())
	{
		yPos = document.body.scrollTop + document.body.clientHeight - this.Height() - 5;
	}
	if (xPos < 0)
	{
		xPos = 0;
	}
	if (yPos < 0)
	{
		yPos = 0;
	}

	this.XPos = xPos;
	this.YPos = yPos;
//alert(xPos);
	XF_MoveElementTo(this.Layer, xPos, yPos);
}

XF_Menu.prototype.AddSeparator = function ()
{
	this.Items[this.Items.length] = null;
}

XF_Menu.prototype.AddItem = function(menuItem)
{
	this.Items[this.Items.length] = menuItem;
}

XF_Menu.prototype.Render = function(menuId)
{
	var html;
	var itemIdx;
	var item;
	var paddingLeft;
	var paddingRight;
	

	if (xf_Is.nav4)
	{
		html = "<table ID=\"xf_tbl_" + menuId + "\" border=\"" + this.BorderWidth + "\" bordercolor=\"" + this.BorderColor + "\" cellspacing=\"0\" cellpadding=\"0\" ";
		if (this.BackgroundColor != null)
		{
			html += "bgcolor=\"" + this.BackgroundColor + "\" ";
		}
		html += " style=\"";
		html += "width=" + this.ItemWidth + "px;";
		html += "height=" + this.Height(false) + "px;";
		if (this.BorderStyle != null && this.BorderWidth != null && this.BorderColor != null)
		{
			html += "border:" + this.BorderStyle + " " + this.BorderWidth + "px " + this.BorderColor + ";";
		}
		html += "\">";

		for (itemIdx in this.Items)
		{
			item = this.Items[itemIdx];
			
			if (item == null)
			{
			}
			else
			{
				html += "<tr ID=\"xf_td_" + itemIdx + "_" + menuId + "\" ";
				if (this.ItemBackgoundColor != null)
				{
					html += "bgcolor=\"" + this.ItemBackgoundColor + "\" ";
				}
				html += " style=\"";
				html += "width:" + this.ItemWidth + "px;";
				html += "height:" + this.ItemHeight + "px;";
				if (this.ItemBackgoundColor != null)
				{
					html += "background-color:" + this.ItemBackgoundColor + ";";
				}
				html += "\">";
				html += "<td ID=\"xf_data_" + itemIdx + "_" + menuId + "\" NOWRAP width=\"" + this.ItemWidth + "\" height=\"" + this.ItemHeight + "\" ";
				if (this.ItemBackgoundColor != null)
				{
					html += "bgcolor=\"" + this.ItemBackgoundColor + "\" ";
				}
				if (this.ItemAlign != null)
				{
					html += " Align=\"" + this.ItemAlign + "\" ";
				}
				if (this.ItemVAlign != null)
				{
					html += " valign=\"" + this.ItemVAlign + "\" ";
				}
				html += " style=\"";
				html += "width:" + this.ItemWidth + "px;";
				html += "height:" + this.ItemHeight + "px;";
				html += "overflow:hidden;";
				if (this.ItemAlign != null)
				{
					html += "text-align:" + this.ItemAlign + ";";
				}
				if (this.ItemVAlign != null)
				{
					html += "vertical-align:" + this.ItemVAlign + ";";
				}
				if (this.ItemBackgroundColor != null)
				{
					html += "background-color:" + this.ItemBackgroundColor + ";";
				}
				if (this.ItemColor != null)
				{
					html += "color:" + this.ItemColor + ";";
				}
				if (this.ItemPaddingLeft != null)
				{
					html += "padding-left:" + this.ItemPaddingLeft + ";";
				}
				if (this.ItemPaddingRight != null)
				{
					html += "padding-right:" + this.ItemPaddingRight + ";";
				}
				html += "font-family:" + this.ItemFont + ";";
				html += "font-size:" + this.ItemFontSize + "px;";
				if (this.ItemFontWeight != null)
				{
					html += "font-weight:" + this.ItemFontWeight + ";";
				}
				html += "cursor:hand;";
				html += "\"><NOBR>";
				if (item.Action != null || item.Function != null)
				{
					html += "<DIV ID=\"xf_lnk_" + itemIdx + "_" + menuId + "\" onMouseOver=\"alert('toto');\" style=\"text-decoration:none;cursor:hand;";
					if (this.ItemColor != null)
					{
						html += "color:" + this.ItemColor + ";";
					}
					html += "font-family:" + this.ItemFont + ";";
					html += "font-size:" + this.ItemFontSize + ";";
					if (this.ItemFontWeight != null)
					{
						html += "font-weight:" + this.ItemFontWeight + ";";
					}
					html += "\" >" + item.Text + "</DIV>";
				}
				else
				{
					html += item.Text;
				}
				html += "</NOBR></td></tr>";
			}
		}
		html += "<tr><td>jhhjkhkj</td></tr>";
		
	}
	else
	{
		html = "<div ID=\"xf_sp_" + menuId + "mnu\" ";
		if (this.CSSPrefix != null)
		{
			html += "class=\"" + this.CSSPrefix + "Menu\" ";
		}
		html += ">";

		html += "<table ID=\"xf_tbl_" + menuId + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ";
		if (this.CSSPrefix != null)
		{
			html += "class=\"" + this.CSSPrefix + "Table\" ";
		}
		html += ">";

		for (itemIdx in this.Items)
		{
//			break;
			item = this.Items[itemIdx];
					
			//xf_DEBUG.Write("item : " + typeof(item));
			if (item == null)
			{
				html += "<tr ID=\"xf_tr_" + itemIdx + "_" + menuId + "\" ";
				html += "onMouseOver=\"";
				html += "XF_MenuOnMouseOver(this, '" + this.Name + "', '" + menuId + "', " + this.Index + ", " + itemIdx + ");";
				html += "\" onClick=\"";
				html += "XF_MenuOnClick(this, '" + this.Name + "', '" + menuId + "', " + this.Index + ", " + itemIdx + ");";
				html += "\" onLoad=\"this.menuObject = xf_MenuManager.GetMenu('" + this.Name + "');\">";
				html += "<td ID=\"xf_data_" + itemIdx + "_" + menuId + "\" ";
				if (this.CSSPrefix != null)
				{
					html += "class=\"" + this.CSSPrefix + "Separator\" ";
				}
				html += ">";
				html += "<HR NOSHADE/>";
				html += "</td></tr>";
			}
			else
			{
				html += "<tr ID=\"xf_tr_" + itemIdx + "_" + menuId + "\" ";
				html += "onMouseOver=\"";
				html += "XF_MenuOnMouseOver(this, '" + this.Name + "', '" + menuId + "', " + this.Index + ", " + itemIdx + ");";
				html += "\" onMouseOut=\"";
				html += "XF_MenuOnMouseOut(this, '" + this.Name + "', '" + menuId + "', " + this.Index + ", " + itemIdx + ");";
				html += "\" onClick=\"";
				html += "XF_MenuOnClick(this, '" + this.Name + "', '" + menuId + "', " + this.Index + ", " + itemIdx + ");";
				html += "\" onLoad=\"this.menuObject = xf_MenuManager.GetMenu('" + this.Name + "');\" ";
				if (this.CSSPrefix != null)
				{
					html += "class=\"" + this.CSSPrefix + "Item\" ";
				}
				html += ">";
				html += "<td ID=\"xf_data_" + itemIdx + "_" + menuId + "\" NOWRAP ";
				html += ">";
				//if (item.Action != null || item.Function != null)
				//{
					html += "<SPAN ID=\"xf_lnk_" + itemIdx + "_" + menuId + "\">";
					
					html += "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\" height=\"100%\">";
					html += "<tr><td valign=\"top\">";
					
					if (this.BeforeMenuImageURL)
					{
						html += "<img src=\"" + this.BeforeMenuImageURL + "\" border=\"0\"/>";
					}
					html += "</td><td ID=\"xf_txt_" + itemIdx + "_" + menuId + "\" width=\"100%\" valign=\"middle\" ";
					if (this.CSSPrefix != null)
					{
						html += "class=\"" + this.CSSPrefix + "Text\" ";
					}
					html += ">";

					html += item.Text + "</td><td valign=\"middle\">";
					
					if (this.SubMenuImageURL && item.SubMenu != null)
					{
						html += "<img src=\"" + this.SubMenuImageURL + "\" border=\"0\"/>";
					}
					html += "</td></tr></table></SPAN>";
				//}
				//else
				//{
				//	html += item.Text;
				//}
				html += "</td></tr>";
			}
		}
	}
	
//	xf_DEBUG.Push();
//	xf_DEBUG.Write(html);
//	xf_DEBUG.Pop();
	
	html += "</table></div>";
//	html += "</div>";
//alert(html);
	return html;
}

function XF_MenuOnClick(srcElem, menuName, menuId, menuIndex, itemIdx)
{
	var menu;
	var menuItem;
	var menuRow;
	var xPos;
	var yPos;
	
	menu = xf_MenuManager.Menus[menuIndex];
	
	menuItem = menu.Items[itemIdx];
	if (menuItem == null)
	{
		return;
	}
	else
	{
		if (menuItem.Action != null)
		{
			menu.Over = false;
			menu.Hide(true);
			window.location.href = menuItem.Action;
		}
		else
		{
			if (menuItem.Function != null)
			{
				menu.Over = false;
				menu.Hide(true);
				//xf_MenuManager.HideMenu(menuName);

				fct = menuItem.Function + "(";
				if (menuItem.Arguments != null)
				{
					fct += menuItem.Arguments;
				}
				fct += ")";

				eval(fct);
			}
		}
	}
}

function XF_MenuOnMouseOver(srcElem, menuName, menuId, menuIndex, itemIdx)
{
	var menu;
	var subMenu;
	var menuItem;
	var menuRow;
	var menuText;
	var xPos;
	var yPos;
	var parent;
	var parentMenu;
	var i;
	var item;
	var ids;
	
	menu = xf_MenuManager.Menus[menuIndex];
	
	menuItem = menu.Items[itemIdx];
	if (menuItem == null)
	{
		return;
	}

	menu.Over = true;
	menu.CancelHide();
	
	if (menu.ShownIdx != -1)
	{
		XF_MenuUnHighLightItem(menu, true);
	}
	
	if (menu.Parent != null)
	{
		menu.Parent.Lock();
	}
	
	menu.ShownIdx = itemIdx;

	//parent = window.event.srcElement;
	parent = srcElem;
	menuRow = null;
	for (i = 0; i < 10; i++)
	{
		if (parent == null)
		{
			break;
		}
		if (parent.id == menuId + "_" + itemIdx)
		{
			menuRow = parent;
			break;
		}
		if (xf_Is.gecko)
		{
			parent = parent.parentNode;
		}
		else
		{
			parent = parent.parentElement;
		}
	}

	if (menuRow == null)
	{
		menuRow = XF_GetElementById("xf_tr_" + itemIdx + "_" + menuId);
	}

	if (menuText == null)
	{
		menuText = XF_GetElementById("xf_txt_" + itemIdx + "_" + menuId);
	}

	if (menuRow != null)
	{
		if (menu.CSSPrefix != null)
		{
			//alert(menuRow.className);
			menuRow.className = menu.CSSPrefix + "ItemOver";
			menuText.className = menu.CSSPrefix + "TextOver";
			//alert(menuRow.className);
		}
	}

	if (menuItem.SubMenu != null)
	{
		xPos = menu.XPos + menu.Width() + menu.SubMenuSpacing;
		yPos = XF_GetYPosition(menuRow);
		//alert(yPos);
		//yPos = menu.YPos;
		
		//yPos -= (menuItem.SubMenu.MenuPaddingTop - menu.MenuPaddingTop);

		menu.ShownItem = menuItem.SubMenu;
		menuItem.SubMenu.Parent = menu;
		//alert(xPos + ' ' + yPos);
		menuItem.SubMenu.Show(xPos, yPos);
	}
}

function XF_MenuOnMouseOut(srcElem, menuName, menuId, menuIndex, itemIdx)
{
	var menu;
	var args = new Array();
	var menuItem;
	var parentMenu;

	//menu = xf_MenuManager.GetMenu(menuName);
	menu = xf_MenuManager.Menus[menuIndex];

	menuItem = menu.Items[itemIdx];
	
	menu.Over = false;

	xf_MenuManager.HideMenu(menuIndex, menu.HidingDelay);

/*
	if (this.ShownItem != null)
	{
		this.ShownItem.Parent = null;
		xf_MenuManager.HideMenu(this.ShownItem.Index, 100);
	}

*/
	window.setTimeout('XF_MenuUnHighLightItem(' + menu.Index + ', false);', 500);
	
	if (menu.Parent != null)
	{
		menu.Parent.UnLock();
	}
}

function XF_MenuUnHighLightItem(args, bForce)
{
	var menu;
	var menuItem;
	var menuRow;
	var menuText;
	var menuId;
	var itemIdx;

	if (typeof(args) == 'number')
	{
		menu = xf_MenuManager.Menus[args];
	}
	else
	{
		menu = args;
	}
	
	if (!bForce)
	{
		if (menu.bLock)
		{
			return;
		}

		if (menu.Over)
		{
			return;
		}
	}

	if (menu.ShownIdx == -1)
	{
		return;
	}
	
	if (menu.ShownItem != null)
	{
		menu.ShownItem.Parent = null;
		menu.ShownItem.Hide(true);
		menu.ShownItem = null;
	}
	
	menuItem = menu.Items[menu.ShownIdx];

	menuRow = XF_GetElementById("xf_tr_" + menu.ShownIdx + "_" + menu.Id);
	menuText = XF_GetElementById("xf_txt_" + menu.ShownIdx + "_" + menu.Id);

	if (menuRow != null)
	{
		if (menu.CSSPrefix != null)
		{
			//alert(menuRow.className);
			menuRow.className = menu.CSSPrefix + "Item";
			menuText.className = menu.CSSPrefix + "Text";
			//alert(menuRow.className);
		}
	}

	menu.ShownIdx = -1;
}

function XF_MenuOnContextMenu(evt)
{
	var menuName;
	
	if (xf_Is.ie4up)
	{
		return !xf_MenuManager.ShowContextMenu(window.event.srcElement, document.body.scrollLeft+event.clientX, document.body.scrollTop+event.clientY);
	}
	if (xf_Is.gecko)
	{
		return !xf_MenuManager.ShowContextMenu(evt.currentTarget, pageXOffset+e.clientX, pageYOffset+e.clientY);
	}
}

var xf_MenuManager = new XF_MenuManager();